<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class OrderCancel extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'order:cancel';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '15分钟取消支付订单';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $times = time();
        $order_data = DB::table("order")->where("order_status",0)->where("update_time","<=",$times - 15 * 60)->where("delete_time",null)->select("id","update_time")->get();
        foreach ($order_data as $k => $v){
            DB::table("order")->where("id",$v->id)->update(["delete_time" => time()]);
            Log::info("订单取消成功:". $v->id);
        }
    }
}
